// Copyright (c) 2000 Just Objects B.V. <just@justobjects.nl>
// Distributable under LGPL license. See terms of license at gnu.org.

package nl.justobjects.pushlet.core;

import java.io.Serializable;
import java.io.Reader;
import java.util.Enumeration;
import java.util.Properties;

/**
 * Represents the event data. TODO: make it as interface.
 *
 * @version $Id: Event.java,v 1.3 2003/08/15 08:37:40 justb Exp $
 * @author Just van den Broecke - Just Objects &copy;
 **/
public class Event implements Serializable {

	private Properties attributes = new Properties();

	private Event() {
	}

	public Event(String subject) {
		attributes.put("subject", subject);
	}

	public Event(Properties theAttributes) {
		attributes = theAttributes;
	}

	public String getSubject() {
		return attributes.getProperty("subject");
	}

	public void setAttribute(String name, String value) {
		attributes.put(name, value);
	}

	public String getAttribute(String name) {
		return attributes.getProperty(name);
	}

	public Enumeration getAttributeNames() {
		return attributes.propertyNames();
	}

	public String toString() {
		return attributes.toString();
	}

	public String toXML() {
		String xmlString = "<event ";
		for (Enumeration e = getAttributeNames(); e.hasMoreElements();) {
			String nextAttrName = (String) e.nextElement();
			String nextAttrValue = getAttribute(nextAttrName);
			xmlString = xmlString + nextAttrName + "=\"" + nextAttrValue + "\" ";
		}

		xmlString += "/>";
		return xmlString;
	}

	public Object clone() {
		// Clone the attributes and assign them to newly created Event.
		return  new Event((Properties) attributes.clone());
	}
}

/*
  * $Log: Event.java,v $
  * Revision 1.3  2003/08/15 08:37:40  justb
  * fix/add Copyright+LGPL file headers and footers
  *
  * Revision 1.2  2003/05/18 16:15:08  justb
  * support for XML encoded Events
  *
  * Revision 1.1.1.1  2002/09/24 21:02:30  justb
  * import to sourceforge
  *
  */
